<?php
try{
			require_once ('../connexion.php');	
			if (!isset($_POST['albumId'])){
				$albumId = "all";
			}else{
				$albumId=$_POST['albumId'];
			}
			if ($albumId=="all"){
				$sqlLimit = 'SELECT * FROM images ORDER BY idProduits LIMIT 1';
				$select = $connection->prepare($sqlLimit, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
				$select->execute();
				$enregistrement=$select->fetch(PDO::FETCH_OBJ);
				
				$sql= 'SELECT * FROM images ORDER BY idProduits';
				$select = $connection->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
				$select->execute();
			}else{
				$sqlLimit = 'SELECT * FROM images WHERE idTypesProd=:albumId ORDER BY idProduits LIMIT 1';
				$select = $connection->prepare($sqlLimit, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
				$select->execute(array(':albumId' => $albumId));
				$enregistrement=$select->fetch(PDO::FETCH_OBJ);
				
				$sql = 'SELECT * FROM images WHERE idTypesProd=:albumId ORDER BY idProduits';
				$select = $connection->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
				$select->execute(array(':albumId' => $albumId));	
			}
			// test si il y a au moins une image
			if($enregistrement==true){
				
				$chemin=$enregistrement->chemin;
				$nom=$enregistrement->nom;
				$descri=$enregistrement->description;	
				?>
				<table class="thumbnail">
					<tr>
						<td class="thumbnailContent">
							<div id="divLargeImg">
								<img id="imgContent" src="images/<?php echo $chemin;?>"/>
							</div>	
							<h3 id="h3Description" class="titleDescriptionGalery"><?php echo $nom;?></h3>
							<p id="descriptionGalerry"><?php echo $descri;?></p>
						</td>
						<td class="thumbnailChoice">	
							<?php
							
							while($enregistrement2 = $select->fetch(PDO::FETCH_OBJ)){
								
									$nom=preg_replace('/"/','&#34;',$enregistrement2->nom); // convertie toutes les "
									$nom=preg_replace('/\'/','&#180;',$nom); // convertie toutes les '
				
									$description=preg_replace('/"/','&#34;',$enregistrement2->description); // convertie toutes les "
									$description=preg_replace('/\'/','&#180;',$description); // convertie toutes les '
							?>
								<div>	
									<img onMouseOver="return loadLargeImage('<?php echo $enregistrement2->chemin;?>','<?php echo $description;?>','<?php echo $nom;?>');" class="littleImage" src="images/<?php echo $enregistrement2->chemin;?>" />					
								</div>
							<?php	
							}
							?>			
						</td>
					</tr>
				</table>						
				<?php 
			}else{
				echo "<h3><p>Oups ! Aucune image . . .</p></h3>";
			}
}catch(Exception $e){
	echo "<h3 class='error'>Impossible de charger la galerie</h3>";
}
?>	